// mixins文件
import html2canvas from 'html2canvas'
export default {
  data () {
    return {
    }
  },
  methods: {
    downImg () {
      const dom = document.getElementById('exportContainer')
      this.exportToImage(dom, '溯源码')
    },
    exportToImage (exportContent, title) {
      html2canvas(exportContent, {
        useCORS: true,
        height: exportContent.scrollHeight - 1, // canvas高, 高度减 1 是为了解决底部出现白线问题
        width: exportContent.scrollWidth // canvas宽
      }).then((canvas) => {
        const imageDataUrl = canvas.toDataURL('image/png')
        const downloadLink = document.createElement('a')
        downloadLink.href = imageDataUrl
        downloadLink.download = `${title}.png`
        downloadLink.click()
      })
    }
  }
}
